import 'dart:io';

import 'package:device_info/device_info.dart';
import 'package:p_location/common/constant/sp_key.dart';
import 'package:p_location/utils/shared_preferences_util.dart';

class DeviceUtil{

  static Future<String> getUniqueId() async {


    DeviceInfoPlugin deviceInfo = DeviceInfoPlugin();
    if (Platform.isIOS) {
      IosDeviceInfo iosDeviceInfo = await deviceInfo.iosInfo;
      print("ios唯一设备码："+iosDeviceInfo.identifierForVendor);
      Map<String, String> params = {};
      params[SPKey.KEY_DEVICE_ID] = iosDeviceInfo.identifierForVendor;
      SharedPreferenceHelp.save(params);
      return iosDeviceInfo.identifierForVendor; // unique ID on iOS
    } else {
      AndroidDeviceInfo androidDeviceInfo = await deviceInfo.androidInfo;
      print("android唯一设备码："+androidDeviceInfo.androidId);
      Map<String, String> params = {};
      params[SPKey.KEY_DEVICE_ID] = androidDeviceInfo.androidId;
      SharedPreferenceHelp.save(params);

      return androidDeviceInfo.androidId; // unique ID on Android
    }
  }
}